package com.lupengning.payment.controller;

import com.lupengning.payment.entity.OrderInfo;
import com.lupengning.payment.enums.OrderStatus;
import com.lupengning.payment.service.OrderInfoService;
import com.lupengning.payment.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lupengning
 * @version 1.0
 * @description:
 * @date 2021/12/28 23:24
 */
@Slf4j
@Api(tags = "订单管理")
@RestController
@RequestMapping("/api/order-info")
@CrossOrigin
public class OrderInfoController {

  @Resource
  private OrderInfoService orderInfoService;

  @GetMapping("/list")
  public R list() {

    List<OrderInfo> list = orderInfoService.listOrderByCreateTimeDesc();
    return R.ok().data("list", list);
  }

  /**
   * 查询本地订单状态
   */
  @ApiOperation("查询本地订单状态")
  @GetMapping("/query-order-status/{orderNo}")
  public R queryOrderStatus(@PathVariable String orderNo) {
    String orderStatus = orderInfoService.getOrderStatus(orderNo);
    if (OrderStatus.SUCCESS.getType().equals(orderStatus)) {//支付成功
      return R.ok();
    }
    return R.ok().setCode(101).setMessage("支付中... ");
  }

}
